package com.weibiao.zhuhai.nowcoder;


public class ListNodeUtil {

	/**common part*/
	public static ListNode initialList( int... vals ) {
		ListNode res = new ListNode( 0x7fffffff );
		ListNode p = new ListNode( vals[ 0 ] );
		res.next = p;

		for( int i = 1; i < vals.length; i++ ) {
			ListNode dummyNode = new ListNode( vals[ i ] );
			p.next = dummyNode;
			p = dummyNode;
		}
		return res.next;
	}

	public static void printList( ListNode head ) {
		boolean firstOne = true;
		while( head != null ) {
			if( firstOne ) {
				firstOne = false;
				System.out.print( head.val );
			} else {
				System.out.print( "->" + head.val );
			}

			head = head.next;
		}
	}

	public static void main( String[] args ) {
		ListNode head = initialList( 0, 1, 1, 1, 2, 3, 3 );
		printList( head );
	}
}
